#!/usr/bin/env python3
# -*- coding: utf_8 -*-

import json
import yaml


def jtoo(s):
    """json string to object
    """
    try:
        return json.loads(s.decode("utf-8"), strict=False)
    except:
        try:
            return json.loads(s, strict=False)
        except:
            pass
    return None


def ytoo(s):
    """yaml string to object
    """

    try:
        return yaml.load(s.decode("utf-8"))
    except:
        try:
            return yaml.load(s)
        except:
            pass
    return None


def stoo(s):
    return jtoo(s) or ytoo(s)


def otoj(o):
    """object to json
    """

    return json.dumps(o)


def otoy(o):
    """object to yaml
    """

    return yaml.dump(o)


# vim: sw=4 ts=4 sts=4 ai et
